package com.example.observer;

import java.util.ArrayList;
import java.util.List;

public class ActivityObservable {

    private List<ActivityObserver> observers = new ArrayList<ActivityObserver>();
    private static ActivityObservable activityObservable;

    public static ActivityObservable getInstance() {
        if (activityObservable == null) {
            activityObservable = new ActivityObservable();
        }
        return activityObservable;
    }

    public void attach(ActivityObserver observer) {
        observers.add(observer);
    }

    public void detach(ActivityObserver observer) {
        observers.remove(observer);
    }

    public void notifyObservers() {
        for (ActivityObserver observer : observers) {
            observer.update();
        }
    }
}
